package com.hmall.api.interceptor;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

/**
 * @author wangyoucheng
 * @date 2025/9/2
 * @description TOD0
 */
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        //从当前线程获取userId
        Long userId = UserContext.getUser();
        //给Feign请求增加请求头user-info。 值是当前线程userId
        if (userId != null) {
            template.header("user-info",userId.toString());
        }

    }
}
